package com.example.personblog.mapper;

import com.example.personblog.entity.Order;
import com.example.personblog.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    // 根据用户id查询订单,一对多案例
    @Select("select * from tb_order where uid = #{uid}") // 假设订单表名为orders，外键为uid
    List<Order> findByUid(int uid);

    //多对一方法查询,根据多个同一用户的订单查询出该用户的个人信息
    @Select("select * from tb_order")
    @Results(
            {
                    @Result(column = "id",property = "id"),
                    @Result(column="order_time",property = "ordertime"),
                    @Result(column="total",property = "total"),
                    @Result(column = "uid",property = "user",javaType = User.class,// // 直接引用BaseMapper的selectById方法
                            //UserMapper继承了 MyBatis-Plus 的BaseMapper<User>,而MyBatis-Plus内置了一个查询ID的方法
                    one=@One(select = "com.example.personblog.mapper.UserMapper.selectById"))
            }
    )
    List<Order>findAll();
}